<html>
	<head></head>
	<body>	
			<?php 
				$db = mysql_connect('oniddb.cws.oregonstate.edu','rundej-db','Hp2tYI0CxEY4U9J9');
				if(mysql_errno($db)){
					echo mysql_errno($db);
				}
				mysql_select_db('rundej-db',$db);
				if($_POST["playerID"] && $_POST["playerFName"] && $_POST["playerLName"] && $_POST["playerRegion"])
				{
					$query = "select * from Region where Region_No = ".$_POST["playerRegion"];
					$result = mysql_query($query, $db);
					$num = mysql_num_rows($result);
					
					if($num > 0)
					{
						echo "Region found, adding player now</br>";
						$query = "INSERT INTO Players values (".$_POST["playerID"].",'".$_POST["playerFName"]."','".$_POST["playerLName"]."',0,".$_POST["playerRegion"].",0,0,' ',0);";
						mysql_query($query,$db);
						?>
						<table border = "5">
							<tr>
								<th>Number</th>
								<th>Fname</th>
								<th>Lname</th>
								<th>Region Name</th>
								<th>Position</th>
								<th>Innings Batted</th>
								<th>Overs Bowled</th>
								<th>Wickets Taken</th>
								<th>Runs Scored</th>
							</tr>
						<?php
						$query = "Select * from Players natural join Region where Number = ".$_POST["playerID"];
						$result = mysql_query($query,$db);
						?><tr><?php
						$row = mysql_fetch_array($result);
						?><td><?php
						echo $row["Number"];
						?></td><td><?php
						echo $row["Fname"];
						?></td><td><?php
						echo $row["Lname"];
						?></td><td><?php
						echo $row["Region_Name"];
						?></td><td><?php
						echo $row["Primary_Position"];
						?></td><td><?php
						echo $row["Innings_Batted"];
						?></td><td><?php
						echo $row["Overs_Bowled"];
						?></td><td><?php
						echo $row["Wickets_Taken"];
						?></td><td><?php
						echo $row["Runs_Scored"];			
						?></td></tr></table><?php
					}
					else
						echo "Did not find Region</br>";
				}
				else
					echo "Error, missing inputs</br>";
				mysql_free_result($result);
				mysql_close($db);
			?>
		
		<a href="players.php">Return to Players page</a>
	</body>
</html>
